
import 'k8w-extend-native';
import { HttpClient as HttpClientBrowser, WsClient as WsClientBrowser } from 'tsrpc-browser';
import { GameClient } from './shared/gameClient/gameClient';
import { GateClient } from './shared/gateClient/gateClient';


declare global {

    /**
     * 运行环境标识,browser|miniapp|nodejs|undefined
     */
    function getCurrEnvKey(): "browser" | "miniapp" | "nodejs" | 'undefined';
}

var getEnvKey = (typeof (getCurrEnvKey) === 'undefined') ? () => 'undefined' : getCurrEnvKey;

switch (getEnvKey()) {
    case "browser":
        globalThis.getGateClient = (gateServerUrl: string): GateClient => {
            return new GateClient((proto, opt) => {
                return new HttpClientBrowser(proto, opt);
            }, gateServerUrl);
        };
        globalThis.getGameClient = (serverUrl: string): GameClient => {
            return new GameClient((proto, opt) => {
                return new WsClientBrowser(proto, opt);
            }, serverUrl);
        };
        break;
    case "miniapp":
        /*
        globalThis.getGateClient = (gateServerUrl: string): GateClient => {
            return new GateClient((proto, opt) => {
                return new HttpClientMiniapp(proto, opt);
            }, gateServerUrl);
        };
        globalThis.getGameClient = (serverUrl: string): GameClient => {
            return new GameClient((proto, opt) => {
                return new WsClientMiniapp(proto, opt);
            }, serverUrl);
        };*/
        break;
    case "nodejs":
        /*
        globalThis.getGateClient = (gateServerUrl: string): GateClient => {
            return new GateClient((proto, opt) => {
                return new HttpClientNodejs(proto, opt);
            }, gateServerUrl);
        };
        globalThis.getGameClient = (serverUrl: string): GameClient => {
            return new GameClient((proto, opt) => {
                return new WsClientNodejs(proto, opt);
            }, serverUrl);
        };*/
        break;
}